package com.hyt.it.ogt.ks.util;

import java.util.Arrays;
import java.util.List;

import org.apache.commons.lang3.StringUtils;

import cn.hutool.core.util.HashUtil;

public class AdmissionNumberEncryptUtil {
    public final static List<Integer> NUM_ARR = Arrays.asList(5,9,0,1,6,7,4,8,2,3);
    public final static List<String> STRING_ARR = Arrays.asList("p","i","a","v","b","q","s","d","k","m","f","y","j","l","o","z","g","r","e","t","u","c","w","x","h","n");

    public static Integer encrypt(String...s) {
        StringBuffer sb = new StringBuffer();
        for (String s1 : s) {
            sb.append(s1);
        }
        return HashUtil.fnvHash(sb.toString());
    }

    public static String encrypt(String str) {
        if (StringUtils.isBlank(str)) {
            return "";
        } else {
            char[] chars = str.toLowerCase().toCharArray();
            StringBuffer sb = new StringBuffer();
            int number = 0;
            for (char c : chars) {
                charToASCII(c);
                Integer n = NUM_ARR.indexOf(c);
                if(n == null) {
                    sb.append(STRING_ARR.indexOf(c));
                } else {
                    sb.append(n);
                }
            }
            return sb.toString();
        }
    }

    private static int charToASCII(char c) {
        return (int) c;
    }

    public static String decrypt(String str) {
        if (StringUtils.isBlank(str)) {
            return "";
        } else {
            char[] chars = str.toLowerCase().toCharArray();
            StringBuffer sb = new StringBuffer();
            for (char c : chars) {
                Integer n = NUM_ARR.indexOf(c);
                if(n == null) {
                    sb.append(STRING_ARR.indexOf(c));
                } else {
                    sb.append(n);
                }
            }
            return sb.toString();
        }
    }

    public static void main(String[] args) {
        Integer s = encrypt("1","");
        System.out.println(s);
    }

}
